package com.pcjavanet.domain;

import org.apache.log4j.Logger;

import com.pcjavanet.util.CommonUtil;

public class PChart extends BaseChart {
	protected static Logger logger = Logger.getLogger( PChart.class );
	private double pBar ;
	private double ucl ; 
	private double lcl ; 
	private int subInspects ;
	
	public int getSubInspects() {
		return subInspects;
	}

	public void setSubInspects(int subInspects) {
		this.subInspects = subInspects;
	}

	public double getpBar() {
		return pBar;
	}

	public void setpBar(double pBar) {
		this.pBar = pBar;
	}
	public double getUcl() {
		if ( subInspects != 0 )
			this.ucl = this.pBar +  3 * Math.sqrt( ( pBar * ( 1 - pBar )  ) /subInspects );
		else 
			logger.error(" subInspects is zero ,so can't get Ucl ");
		return ucl ; 
	}

	public void setUcl(double ucl) {
		this.ucl = ucl;
	}

	public double getLcl() {
		if ( subInspects != 0 )
			this.ucl = this.pBar -  3 * Math.sqrt( ( pBar * ( 1 - pBar )  ) /subInspects );
		else 
			logger.error(" subInspects is zero ,so can't get Ucl ");
		return this.lcl ;
	}

	public void setLcl(double lcl) {
		this.lcl = lcl;
	}
	
	public void calculatePBar (int totalDefects , int totalInspects ) {
		if ( totalInspects !=0 )
			pBar = CommonUtil.getPrecision( ((double) totalDefects )/ totalInspects ) ; 
	}
}
